<?php
//session_start();
include_once('check_login.php');
include_once(dirname(__FILE__) . '/config.php');
require_once(dirname(__FILE__) . '/module/modules_lib.php');
$current_url = $_SERVER['REQUEST_URI'];
?>
<div class="page-sidebar-wrapper">
    <div class="page-sidebar navbar-collapse collapse">
        <!-- add "navbar-no-scroll" class to disable the scrolling of the sidebar menu -->
        <!-- BEGIN SIDEBAR MENU -->
        <ul class="page-sidebar-menu" data-auto-scroll="true" data-slide-speed="200">
            <li class="sidebar-toggler-wrapper">
                <!-- BEGIN SIDEBAR TOGGLER BUTTON -->
                <div class="sidebar-toggler hidden-phone">
                </div>
                <!-- BEGIN SIDEBAR TOGGLER BUTTON -->
            </li>
            <li class="sidebar-search-wrapper">
                <!-- BEGIN RESPONSIVE QUICK SEARCH FORM -->
                <form class="sidebar-search" action="extra_search.html" method="POST">
                    <div class="form-container">
                        <div class="input-box">
                            <a href="javascript:;" class="remove">
                            </a>
                            <input type="text" placeholder="Tìm..."/>
                            <input type="button" class="submit" value=" "/>
                        </div>
                    </div>
                </form>
                <!-- END RESPONSIVE QUICK SEARCH FORM -->
            </li>

            <li class="start <?php echo '' . (stripos($current_url, "dashboard.php") === false ? : 'active') ?> ">
                <a href="<?php echo $url;?>/dashboard.php">
                    <i class="fa fa-home"></i>
                    <span class="title">
                        Trang chủ
                    </span>

                </a>
            </li>
            <?php
            $parents = get_parent_only($_SESSION['id']);
//            echo '<pre>';
//            var_dump($parents);
//            die();
            foreach ($parents as $parent) {
                                
                $children = get_children($parent['id']);
                //echo 'parent '.$parent['id'] .'count child ='.count($children).'<br/>';
                if (count($children) == 0) {
                    ?>
                    <li class="<?php echo '' . (stripos($current_url, $parent['module_code']) === false ? : 'active') ?>">
                        <a href="<?php echo $url.'/'.$parent['link']; ?>">

                            <span class="title">
                                <?php echo $parent['name']; ?>
                            </span>
                        </a>
                    </li>

                    <?php
                } else {
                    
                    ?>
                    <li class="<?php echo '' . (stripos($current_url, $parent['module_code']) === false ? : 'active') ?>">
                        <a href="<?php echo $url.'/'.$parent['link']; ?>">
                            <i class=""></i>
                            <span class="title">
                                <?php echo $parent['name']; ?>
                            </span>
                            <span class="arrow ">
                            </span>
                        </a>
                        <ul class="sub-menu">
                        <?php foreach($children as $child){?>
                        <li class="<?php echo '' . (stripos($current_url, $child['module_code']) === false ? : 'active') ?>">
                                <a href="<?php echo $url.'/'.$child['link']; ?>">
                                    <?php echo $child['name'] ?>
                                </a>
                            </li>
                        <?php }?>
                        </ul>    
                    </li>
                    <?php
                }
            }
            ?>

            
        </ul>
        <!-- END SIDEBAR MENU -->
    </div>
</div>